const mqHost = process.env.MQ_HOSTNAME || "10.10.10.23";
const mqPort = process.env.MQ_PORT || 5672;
const mqUsername = process.env.MQ_USERNAME||'admin';
const mqPassword = process.env.MQ_PWD||'admin123456';;
const mqProtocol = process.env.MQ_PROTOCOL || 'amqp'
const mqVhost = process.env.MQ_VHOST || 'paas-test';
const exchangeName = 'exchange_direct_saas'; //交换机
const queueName = 'track_queue_node_new';//正常队列名
const routingKey = 'saasIsolution';//正常队列路由key
const exceptionQueueName = 'track_queue_node_exception';//异常队列名
const exceptionRoutingKey = 'exceptionRoutingKey' //异常队列路由key
const config = {
    "vhosts": {
        "/": {
            "publicationChannelPools": { //使用池通道来发布消息.为每个虚拟主机创建两个池 一个用于确认通道，另一个用于常规通道。但在第一次使用之前不会创建两个池（默认autostart: false）空闲通道会自动从池中驱逐
                "regularPool": {
                    "max": 10,
                    "min": 5,
                    "evictionRunIntervalMillis": 10000,
                    "idleTimeoutMillis": 60000,
                    "autostart": true
                },
                "confirmPool": {
                    "max": 10,
                    "min": 5,
                    "evictionRunIntervalMillis": 10000,
                    "idleTimeoutMillis": 60000,
                    "autostart": true
                }
            },
            "connectionStrategy": "random",
            "connection": {
                "slashes": true,
                "protocol": mqProtocol,
                "hostname": mqHost,
                "user": mqUsername,
                "password": mqPassword,
                "port": mqPort,
                "vhost": mqVhost,
                "options": {
                    "heartbeat": 60,//心跳时间。 如果你的任务执行时间比较长，调大此配置。 rabbit-server的heartbeat 默认为60
                    "connection_timeout": 10000,
                    "channelMax": 100
                },
                "socketOptions": {
                    "timeout": 10000
                },
                "management": {
                    "options": {
                        "timeout": 1000
                    }
                },
                "retry": {
                    "min": 1000,
                    "max": 60000,
                    "factor": 2,
                    "strategy": "exponential" //exponential:指数配置将导致 rascal 以指数增加的间隔（最多一分钟）重试连接。间隔会随机调整，这样如果您有多个服务，它们就不会同时重新连接。 linear: 线性配置将导致 rascal 以线性增加的间隔（一到五秒之间）重试连接
                }
            },
            "exchanges": {//定义exchange
                [exchangeName]: {
                    "type": "direct",
                    "options": {
                        "durable": true
                    }
                }
            },
            "queues": { //定义queue
                [queueName]: {
                    "options": {
                        "autoDelete": false,
                        "durable": true
                    }
                },
                [exceptionQueueName]: {
                    "options": {
                        "autoDelete": false,
                        "durable": true
                    }
                }
            },
            "bindings": {//定义binding
                "b1": {
                    "source": exchangeName,
                    "destination": queueName,
                    "destinationType": "queue",
                    "bindingKey": routingKey
                },
                "b2": { //定义将异常队列绑定到exchange的binding
                    "source": exchangeName,
                    "destination": exceptionQueueName,
                    "destinationType": "queue",
                    "bindingKey": exceptionRoutingKey
                }
            }
        }
    },
    "subscriptions": {//订阅消息
        "s1": {
            "queue": queueName,
            "vhost": "/",
            "prefetch": 1,
            "retry": {
                "delay": 1000
            }
        },
        "s2": {
            "queue": exceptionQueueName,
            "vhost": "/",
            "prefetch": 1,
            "retry": {
                "delay": 1000
            }
        }
    },
    "publications": {//发布消息
        "p1": {
            "vhost": "/",
            "exchange": exchangeName,
            "routingKey": routingKey,
            "confirm": true,
            "options": {
                "persistent": true
            }
        },
        "p2": { //定义将消息发送到异常队列的发布设置
            "vhost": "/",
            "exchange": exchangeName,
            "routingKey": exceptionRoutingKey, //将消息发送到异常队列的routing key
            "confirm": true,
            "options": {
                "persistent": true
            }
        }
    }
}
module.exports = config;